package com.etone.smartAudit.mapstruct;

import com.etone.smartAudit.domain.DataModel;
import com.etone.smartAudit.dto.dataModel.DataModelDTO;
import com.etone.smartAudit.dto.iapDataModel.IapDataModelDTO;
import com.etone.smartAudit.vo.dataModel.DataModelDetailVO;
import org.mapstruct.*;

/**
 * @author: sovy
 * @date: 2020/11/12
 * @description:
 */
@Mapper(componentModel = "spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, imports = {com.etone.smartAudit.dto.FileDTO.class, com.etone.smartAudit.vo.FileVO.class})
public interface DataModelMapstruct {

    @Mappings(
            @Mapping(target = "dataExamples", expression = "java(com.alibaba.fastjson.JSONArray.parseArray(dataModel.getDataExamples(),FileVO.class))")
    )
    DataModelDetailVO getDataModelDetailVO(DataModel dataModel);

    @Mappings(
            @Mapping(target = "dataExamples", expression = "java(com.alibaba.fastjson.JSONArray.parseArray(dataModel.getDataExamples(),FileDTO.class))")
    )
    IapDataModelDTO getIapDataModelDTO(DataModel dataModel);

    @Mappings(
            @Mapping(target = "dataExamples", expression = "java(com.alibaba.fastjson.JSONArray.toJSONString(dataModelDTO.getDataExamples()))")
    )
    void copy2DataModel(@MappingTarget DataModel dataModel, DataModelDTO dataModelDTO);
}
